<?php
class LastMatchForm extends CFormModel
{
	public $team1;	
	public $totalMatch = 20;	
	public $local;
	public $listTeam1;	
	public $listLocal;
	public $matchs;
	public $dataprovider;
	public $valid = false;
	public $sintesis;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
				// name, email, subject and body are required
				array('team1, local', 'required'),
				array('totalMatch', 'matchFilter')
		);
	}

	public function matchFilter($attribute,$params)
	{		
			if ($this->totalMatch<1)
				$this->addError('totalMatch','El valor debe ser mayor a cero.');
			if ($this->totalMatch>50)
				$this->addError('totalMatch','El valor no puede ser mayor a 50.');
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
				'team1'=>'Equipo:',				
				'totalMatch'=>'Cantidad Partidos',
				'local'=>'Localia:',
		);
	}

	public function getLastMatch(){
		$aux = $this->totalMatch;
		//localia local1 visitante2 neutral3 todas4		
		if ($this->local==1){
			return $dao=Dao::Instance()->getLastMatch($this->team1,$aux);
		}else if ($this->local==2){
			return $dao=Dao::Instance()->getLastMatchVisitante($this->team1,$aux);
		}else if ($this->local==3){
			return $dao=Dao::Instance()->getLastMatchNeutral($this->team1,$aux);
		}else if ($this->local==4){
			return $dao=Dao::Instance()->getLastMatchTodas($this->team1,$aux);
		}
	}
}